﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Globalization;

namespace LastfmNet
{
    public class LastfmResponse
    {
        private bool isOK = false;
        private XmlNode mainNode;

        public LastfmResponse(string xmlReponseString)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(xmlReponseString);
            XmlElement lfmNode = xmlDocument.DocumentElement;
            mainNode = lfmNode.FirstChild;
            if (lfmNode.Attributes["status"].Value.ToLowerInvariant() == "ok")
            {
                isOK = true;
            }
            else
            {
                isOK = false;
                if (string.IsNullOrEmpty(mainNode.InnerText))
                {
                    throw LastfmException.CreateException(mainNode.Attributes["code"].Value.ToInteger());
                }
                else
                {
                    throw new LastfmException(mainNode.InnerText);
                }
            }
        }

        public bool IsOK
        {
            get
            {
                return isOK;
            }
        }

        public XmlNode MainNode
        {
            get
            {
                return mainNode;
            }
            set
            {
                mainNode = value;
            }
        }
    }
}
